package com.ims.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ims.dao.UserLogMapper;
import com.ims.pojo.UserLog;
import com.ims.service.UserLogService;
import com.ims.util.PageResult;
import com.ims.util.QueryPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author yekka1
 * @description: TODO
 * @date 2022/9/10 12:19
 */
@Service
public class UserLogServiceImpl extends ServiceImpl<UserLogMapper, UserLog> implements UserLogService {

    @Autowired
    private UserLogMapper userLogMapper;

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    public PageResult<UserLog> findPage(QueryPageBean queryPageBean) {
        QueryWrapper<UserLog> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(queryPageBean.getQueryString())) {
            wrapper.like("username", queryPageBean.getQueryString());
        }
        if (StringUtils.hasText(queryPageBean.getOrderColumn()) && StringUtils.hasText(queryPageBean.getOrderRule())) {
            wrapper.orderBy(true, queryPageBean.getOrderRule().equals("asc"), queryPageBean.getOrderColumn());
        }
        Page<UserLog> page = new Page<>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        page = userLogMapper.selectPage(page, wrapper);
        return new PageResult<>(page.getTotal(), page.getRecords());
    }
}
